package com.hzjq.encrypt.pop

import android.content.Context
import com.hzjq.encrypt.R
import com.hzjq.encrypt.bean.Jbqy
import com.hzjq.encrypt.util.KeyBoradX
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.pop_jbqy_layout.view.*

class JbqyEditorPop : CenterPopupView {

    private lateinit var jbqy:Jbqy
    private lateinit var c:OnJbqyEditorCallback

    constructor(context: Context) : super(context)

    override fun getImplLayoutId(): Int {
       return R.layout.pop_jbqy_layout
    }

    override fun onCreate() {
        jbqyPopJdEt.setText(jbqy.jbqyjd)
        jbqyPopWdEt.setText(jbqy.jbqywd)
        jbqyPopBjmEt.setText(jbqy.jbqybj)
        jbqyPopQssjEt.setText(jbqy.jbqssj)
        jbqyPopJzsjEt.setText(jbqy.jbjzsj)

        jbqyPopCancelText.setOnClickListener {
            hideKeyBord()
            dismiss()
        }

        jbqyPopSureText.setOnClickListener {
            hideKeyBord()
            dismiss()
            jbqy.jbqyjd = jbqyPopJdEt.text.toString()
            jbqy.jbqywd = jbqyPopWdEt.text.toString()
            jbqy.jbqybj = jbqyPopBjmEt.text.toString()
            jbqy.jbqssj = jbqyPopQssjEt.text.toString()
            jbqy.jbjzsj = jbqyPopJzsjEt.text.toString()
            c.onLgEditor(jbqy)
        }
    }


    private fun hideKeyBord(){
        KeyBoradX.hideKeyBoard(jbqyPopJdEt)
        KeyBoradX.hideKeyBoard(jbqyPopWdEt)
        KeyBoradX.hideKeyBoard(jbqyPopBjmEt)
        KeyBoradX.hideKeyBoard(jbqyPopQssjEt)
        KeyBoradX.hideKeyBoard(jbqyPopJzsjEt)
    }

    interface OnJbqyEditorCallback {
        fun onLgEditor(jbqy: Jbqy)
    }

    companion object {
        fun show(context: Context, c: OnJbqyEditorCallback, data: Jbqy?){
            val pop = JbqyEditorPop(context)
            if(data != null) {
                pop.jbqy = data
            } else {
                pop.jbqy = Jbqy()
            }
            pop.c = c
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
        }
    }
}